package com.example.demo.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.common.Result;
import com.example.demo.entity.Lifecycle;
import com.example.demo.entity.Store;
import com.example.demo.mapper.LifecycleMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/lifecycle")
public class LifecycleController {
    @Resource
    LifecycleMapper lifecycleMapper;

    @GetMapping
    public Result findPage(@RequestParam(defaultValue = "1") Integer pageNum,
                           @RequestParam(defaultValue = "40") Integer pageSize,
                           @RequestParam(defaultValue = "") String search){
        LambdaQueryWrapper<Lifecycle> wrapper = Wrappers.<Lifecycle>lambdaQuery();
        if (StrUtil.isNotBlank(search)){
            wrapper.like(Lifecycle::getGcode, search);
        }
        Page<Lifecycle> LifecyclePage = lifecycleMapper.selectPage(new Page<>(pageNum, pageSize),wrapper);
        return Result.success(LifecyclePage);
    }

}
